package com.mrs.exception;

import com.mrs.common.HttpEnum;
import com.mrs.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * description: GlobalExceptionHandler
 * date: 2022/7/15 20:09
 * author: MR.孙
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public Result  runtimeException(RuntimeException e){
        return Result.fail(HttpEnum.Code.UNAUTHORIZED,e.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result businessException(BusinessException e){
        log.info(e.getMessage());
        return Result.fail(e.getCode(),e.getMessage());
    }

}
